package net.xdclass.service.impl;

import lombok.extern.slf4j.Slf4j;
import net.xdclass.interceptor.LoginInterceptor;
import net.xdclass.manager.DomainManager;
import net.xdclass.model.DomainDO;
import net.xdclass.service.DomainService;
import net.xdclass.vo.DomainVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author ：zhouyang
 * @date ：Created in 2022/5/11 16:26
 * @modified By：
 * @version: $
 */
@Service
@Slf4j
public class DomainServiceImpl implements DomainService {
    @Autowired
    private DomainManager domainManager;

    @Override
    public List<DomainVO> listAll() {
        Long accountNo = LoginInterceptor.threadLocal.get().getAccountNo();
        List<DomainDO> customdomainDOS = domainManager.listCustomDomain(accountNo);
        List<DomainDO> officaldomainDOS = domainManager.listOfficialDomain();
        customdomainDOS.addAll(officaldomainDOS);
        return customdomainDOS.stream().map(obj -> beanProcess(obj)).collect(Collectors.toList());
    }

    private DomainVO beanProcess(DomainDO domainDO) {

        DomainVO domainVO = new DomainVO();

        BeanUtils.copyProperties(domainDO, domainVO);

        return domainVO;

    }
}
